// const Context = require('hexo-cli/lib/context');
// const  { Context, Next }  = require('koa');
const JWT = require('jsonwebtoken');
// console.log(Context,Next);

const Auth = async (ctx, next) => {
  const { authorization = '' } = ctx.request.header;
  const token = authorization.replace('Bearer ', '');
  const info = JWT.verify(token, "my_token");
  console.log('前端传递的token', token);
  console.log('解析token', info);
  if (info) {
    ctx.state.info = info; // 将信息存放到 state 中
  } else {
    ctx.body = {
      code: 416,
      message: "当前账号登录过期，请重新登录",
      data: null
    }
    // ctx.throw(401, 'token error');
  }
  await next();
};

// export default Auth;
module.exports = Auth
